package cp3120.ucm.client;

import cp3120.dao.DAOFactory;
import cp3120.model.Flight;
import cp3120.ucm.UCController;
import cp3120.view.FlightView;
import cp3120.view.MainUI;

/**
 *
 * @author Adam Scarr <scarr.adam@gmail.com>
 * PRECONDITION: A request to update a flight has been made<br>
 * POST-CONDITION: The system updates and displays the main UI <br>
 * 1. System gets the updated Flight from the FlightVeiw<br>
 * 2. System updates the flight in the database to match the update Flight<br>
 * 3. Syetem removes the FlightVeiw<br>
 * 4. Syetem updates the main UI<br>
 */
public class UCUpdateFlight implements UCController {
    private FlightView view;

    /**
     * Constructor
     * @param flight the FlightVeiw containing the updated flight
     */
    public UCUpdateFlight(FlightView flight) {
        this.view = flight;
    }

    /**
     * runs this UC
     */
    public void run() {
        Flight flight = view.getFlight();

        DAOFactory.getFlightDAO().updateFlight(flight);

        view.dispose();
        MainUI.getInstance().update();
    }


}
